<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="./mycss/login.css" type="text/css">
    <link rel="shortcut icon" href="./favicon.ico" />
    <title>登录</title>
</head>
<body>
    <div class="login clearfix">
        <div class="col-md-12 column">
            <h1 class="text-center" style="margin-top: 80px;">
                IAIA短视频
            </h1>
            <div role="form" style="margin-top: 80px;">
                <div class="form-group">
                    <label for="exampleInputEmail1">用户名</label>
                    <input type="text" class="form-control" name="username" id="username" />
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码</label>
                    <input type="password" class="form-control" name="password" id="password" />
                </div>

                <div class="row checkbox">
                    <label></label>
                    <label class="pull-right hide" id="cklogin" style="color: red;">账户或密码出错！</label>
                </div>
                <div class="row " style="padding-right:20px">
                    <button class="btn btn-primary btn-lg pull-right " onclick="login()">登录</button>
                    <a class="btn btn-primary btn-lg pull-right loginbtn" href="regist.html">注册</a>
                </div>
                <div class="row " style="padding-right:20px">
                	
                </div>
            </div>
        </div>
    </div>
    <script src="./jQuery/jQuery-2.1.4.min.js"></script>
    <script src="./bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function login() {
            // window.location.href = "./index.html?username=yhl&userid=2";
            if(checkNull()){
                var url = 'user/login.do';
                var username = $('#username').val();
                var password = $('#password').val();
                var data = {
                    'username': username,
                    'password': password
                }
                $.ajax({
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: data,
                    success: function (data) {
                        if (data.code == 1) {
                            window.location.href = "./index.html?username="+data.username+"&userid="+data.userid;
                        } else {
                            document.getElementById("cklogin").className = "pull-right";
                        }
                    },
                    error: function () {
                        
                        alert("连接服务器异常！");            
                    }
                })
            }
        }
        function checkNull(){
            if ($("#username").val()==""){
                alert("请输入账号！");
            }else{
                if($("#password").val()==""){
                    alert("请输入密码");
                }else{
                    return true;
                }
            }
        }
    </script>
</body>

</html>